package com.liuzhongni.wahahanews.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.liuzhongni.wahahanews.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/16.
 */
public class ListViewAdapterOfMyself extends BaseAdapter {
    private ArrayList<String> title;
    private ArrayList<Integer> image;
    private String[] titleData = {"我的消息", "金币商城", "我的任务", "我的钱包", "离线阅读", "活动广场", "游戏中心", "我的邮箱", "邀请好友"};
    private int[] imageData = {R.mipmap.iconfont_myself_xiaoxi, R.mipmap.iconfont_myself_shangcheng, R.mipmap.iconfont_myself_renwu, R.mipmap.iconfont_myself_qianbao, R.mipmap.iconfont_myself_lixian, R.mipmap.iconfont_myself_huodongact, R.mipmap.iconfont_myself_youxifenlei, R.mipmap.iconfont_myself_youxiang, R.mipmap.iconfont_myself_yaoqinghaoyou};
    private Context context;

    public ListViewAdapterOfMyself(Context context) {
        this.context = context;
        init();
    }

    private void init() {
        title=  new ArrayList<>();
        image = new ArrayList<>();
        for (int i = 0; i < titleData.length; i++) {
            title.add(titleData[i]);
            image.add(imageData[i]);
        }

    }

    @Override
    public int getCount() {
        return title.size();
    }

    @Override
    public Object getItem(int position) {
        return title.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyselfViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.myself_listview_item, null);
            holder = new MyselfViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyselfViewHolder) convertView.getTag();
        }
        holder.imageViewTitle.setImageResource(image.get(position).intValue());
        holder.textViewTitleName.setText(title.get(position));
        switch (position){
            case 1:
                holder.textViewDigest.setText("能赚能花,土豪当家!");
                break;
            case 6:
                holder.textViewDigest.setText("网易游戏.年度大杂烩");
                break;
            case 8:
                holder.textViewDigest.setText("邀请好友送百兆流量");
                break;
            default:
                holder.textViewDigest.setText("");
                break;
        }
        return convertView;
    }

    public class MyselfViewHolder {
        private ImageView imageViewTitle;
        private TextView textViewTitleName;
        private TextView textViewDigest;


        public MyselfViewHolder(View view) {
            imageViewTitle = (ImageView) view.findViewById(R.id.myself_listview_item_iv_title);
            textViewTitleName = (TextView) view.findViewById(R.id.myself_listview_item_tv_name);
            textViewDigest = (TextView) view.findViewById(R.id.myself_listview_item_tv_digest);
        }
    }
}
